﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public static double bienTam;
    public static string stoanTu;
    #region"hienThi 0==>9"
    public void hienThi(object sender, EventArgs e)
    {

        Button a = (Button)sender;
        txtHienThi.Text += a.Text;
    }
    protected void btn0_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn1_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn2_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn3_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn4_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn5_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn6_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn7_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn8_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn9_Click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    protected void btn0_click(object sender, EventArgs e)
    {
        hienThi(sender, e);
    }
    #endregion

    protected void btnCong_Click(object sender, EventArgs e)
    {
        bienTam = double.Parse(txtHienThi.Text);
        txtHienThi.Text = "";
        stoanTu = "+";
    }
    protected void btnTru_Click(object sender, EventArgs e)
    {
        bienTam = double.Parse(txtHienThi.Text);
        txtHienThi.Text = "";
        stoanTu = "-";
    }
    protected void btnNhan_Click(object sender, EventArgs e)
    {
        bienTam = double.Parse(txtHienThi.Text);
        txtHienThi.Text = "";
        stoanTu = "*";
    }
    protected void btnChia_Click(object sender, EventArgs e)
    {
        bienTam = double.Parse(txtHienThi.Text);
        txtHienThi.Text = "";
        stoanTu = "/";
    }

    protected void btnBang_Click(object sender, EventArgs e)
    {
        //double soThuNhat = bienTam;
        double kq;
        double soThuHai = double.Parse(txtHienThi.Text);
        //txtHienThi.Text = soThuNhat.ToString();
        if (stoanTu == "+")
        {
            kq = bienTam + soThuHai;
            txtHienThi.Text = kq.ToString();
        }
        if (stoanTu == "-")
        {
            kq = bienTam - soThuHai;
            txtHienThi.Text = kq.ToString();
        }
        if (stoanTu == "*")
        {
            kq = bienTam * soThuHai;
            txtHienThi.Text = kq.ToString();
        }
        if (stoanTu == "/" && soThuHai != 0)
        {
            kq = bienTam / soThuHai;
            txtHienThi.Text = kq.ToString();
        }
    }
    protected void  btnClear_Click(object sender, EventArgs e)
    {
            bienTam = 0;
            txtHienThi.Text = ""; 
    }
}